<template>
	<view class="area_partner">
		<view class="list" @tap="showPicker('region')">
			<view class="type">所选区域</view>
			<view class="list_right">
				<view>{{showaddress}}</view>
				<image class="l_img" src="../../static/images/location.png" mode=""></image>
			</view>
		</view>
		<view class="list">
			<view class="type">申请人姓名</view>
			<view class="list_right">
				<input class="input" v-model="contactName"  type="text" placeholder="请输入姓名">
			</view>
		</view>
		<view class="list">
			<view class="type">申请人电话</view>
			<view class="list_right">
				<input class="input" v-model="contactPhone"  type="text" placeholder="请输入电话">
			</view>
		</view>
		<view class="list">
			<view class="type">身份证号</view>
			<view class="list_right">
				<input class="input" v-model="idCardNum" type="text" placeholder="请输入身份证号">
			</view>
		</view>
		<view class="list">
			<view class="type">支付宝账号</view>
			<view class="list_right">
				<input class="input" v-model="aliAccount" type="text" placeholder="请输入支付宝账号">
			</view>
		</view>
		<view class="list">
			<view class="type">银行名称</view>
			<view class="list_right">
				<input class="input" v-model="bankName" type="text" placeholder="请输入银行名称">
			</view>
		</view>
		<view class="list">
			<view class="type">银行卡号</view>
			<view class="list_right">
				<input class="input" v-model="bankNumber" type="text" placeholder="请输入银行卡号">
			</view>
		</view>
		<view class="list list1">
			<view class="type">开户行地址</view>
			<view class="list_right">
				<input class="input" v-model="bankOpName" type="text" placeholder="请输入开户行地址">
			</view>
		</view>
		<view class="list list1">
			<view class="type">上级合伙人/代理编号</view>
			<view class="list_right">
				<input class="input" v-model="pnum" type="text" placeholder="请输入">
			</view>
		</view>
		<view class="name" style="margin:100rpx 0 0 100rpx;">备注：{{remark}}</view>
		<view class="btn" @click="subinfo" v-show="status==0 || status==3">提交申请</view>
		<view class="btn" v-show="status==1">审核中</view>
		<view class="btn" v-show="status==2">已通过</view>
		<view class="btn" @click="guanli" v-show="status==2">后台管理</view>
		
		
		<w-picker mode="region" @confirm="onConfirm($event,'region')" ref="region"></w-picker>
	</view>
</template>

<script>
	import wPicker from '@/components/w-picker/w-picker.vue';
	export default {
		components:{
			wPicker
		},
		data() {
			return {
				showaddress:'请选择',
				province:'请选择',
				provinceCode:'',
				cityCode:'',
				areaCode:'',
				bankOpName:'',
				bankNumber:'',
				bankName:'',
				aliAccount:'',
				idCardNum:'',
				contactName:'',
				contactPhone:'',
				pnum:'',
				userinfo:[],
				has:0,
				status:0,
				remark:''
			}
		},
		onShow() {
			this.userinfo=uni.getStorageSync('user');
			this.getinfo();
		},
		methods: {
			showPicker(type) {
				this.$refs[type].show();
			},
			onConfirm(res, type) {
				switch (type) {
					case "region":
					console.log(res);
						this.showaddress = res.result;
						this.provinceCode = res.value[0];
						this.cityCode = res.value[1];
						this.areaCode = res.value[2];
						this.province = res.obj.province.label;
						this.city = res.obj.city.label;
						this.area = res.obj.area.label;
						break;
				}
				console.log(this.province);
			},
			getinfo(){
				var that=this;
				this.$http.get('shop/getMyArea',{}).
				then(function (response) {
					var data=response.data;
					console.log(data);
					if(data.has==1){
						var data = data.data;
						that.contactPhone=data.contactPhone;
						that.address=data.address;
						that.showaddress = data.province+data.city+data.area;
						that.bankOpName=data.bankOpName;
						that.bankNumber=data.bankNumber;
						that.pnum=data.topshopnum;
						that.bankName=data.bankName;
						that.aliAccount=data.aliAccount;
						that.idCardNum=data.idCardNum;
						that.contactName=data.contactName;
						that.status=data.status;
						that.province=data.province;
						that.provinceCode=data.provinceCode;
						that.city=data.city;
						that.cityCode=data.cityCode;
						that.area=data.area;
						that.areaCode=data.areaCode;
						that.remark=data.remarks?data.remarks:'无';
						that.id = data.id;
					}
				}).catch(function (error) {
					console.log(error);
				});
			},
			guanli(){
				uni.navigateTo({
					url:'/pages/areaPartnerAdmin/areaPartnerAdmin?id='+this.id
				})
			},
			subinfo(){
				
				if(this.contactName==''||this.contactName==undefined||this.contactName==null){
					uni.showToast({
						icon:'none',
						title:'请填写申请人'
					})
					return;
				}
				if(this.contactPhone==''||this.contactPhone==undefined||this.contactPhone==null){
					uni.showToast({
						icon:'none',
						title:'请填写联系电话'
					})
					return;
				}
				if(this.bankOpName==''||this.bankOpName==undefined||this.bankOpName==null){
					uni.showToast({
						icon:'none',
						title:'请填写开户行'
					})
					return;
				}
				if(this.bankName==''||this.bankName==undefined||this.bankName==null){
					uni.showToast({
						icon:'none',
						title:'请填写银行名称'
					})
					return;
				}
				if(this.bankNumber==''||this.bankNumber==undefined||this.bankNumber==null){
					uni.showToast({
						icon:'none',
						title:'请填写银行卡号'
					})
					return;
				}
				if(this.aliAccount==''||this.aliAccount==undefined||this.aliAccount==null){
					uni.showToast({
						icon:'none',
						title:'请填写支付宝账号'
					})
					return;
				}
				
				if(this.idCardNum==''||this.idCardNum==undefined||this.idCardNum==null){
					uni.showToast({
						icon:'none',
						title:'请填写身份证号'
					})
					return;
				}
				if(this.pnum==''||this.pnum==undefined||this.pnum==null){
					uni.showToast({
						icon:'none',
						title:'请填写上级编号'
					})
					return;
				}
				
				var that=this;
				var title='确认提交申请吗？';
				uni.showModal({
				    title: '提示',
				    content: title,
				    success: function (res) {
				        if (res.confirm) {
							that.$http.get('shop/addAreaApply',{'bankOpName':that.bankOpName,'bankNumber':that.bankNumber,'bankName':that.bankName,'aliAccount':that.aliAccount,'idCardNum':that.idCardNum,'contactName':that.contactName,'pnum':that.pnum,'contactPhone':that.contactPhone,'province':that.province,'city':that.city,'area':that.area,'provinceCode':that.provinceCode,'cityCode':that.cityCode,'areaCode':that.areaCode}).
							then(function (response) {
								if(response.Code==-1){
									uni.showToast({
										icon:'none',
										title:response.msg
									})
									return;
								}else{
									uni.showToast({
										icon:'none',
										title:'提交成功，请耐心等待审核！'
									})
									var clock=setInterval(function(){
										clearInterval(clock);
										uni.navigateBack();
									},1500);
								}
							}).catch(function (error) {
								console.log(error);
							});
				        }
				    }
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.area_partner{
		width: 100%;
		.btn{
			margin: 100rpx auto 0;
			width: 690rpx;
			background: #6686f5;
			color: #fff;
			font-size: 32rpx;
			font-weight: bold;
			border-radius: 48rpx;
			height: 96rpx;
			line-height: 96rpx;
			text-align: center;
		}
		.list{
			border-top: 1px solid #e5e5e5;
			padding: 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			&.list1{
				border-bottom: 1px solid #e5e5e5;
			}
			.list_right{
				display: flex;
				align-items: center;
				color: #333;
				font-size: 32rpx;
				.input{
					text-align: right;
					color: #333;
					font-size: 28rpx;
				}
				.l_img{
					margin-left: 10rpx;
					width: 32rpx;
					height: 32rpx;
				}
			}
			.type{
				color: #333;
				font-size: 32rpx;
			}
		}
	}
</style>
